package com.dhf.framework.system.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.dhf.framework.base.mybatis.core.page.Pagination;
import com.dhf.framework.common.BaseController;
import com.dhf.framework.system.entity.SysRole;
import com.dhf.framework.system.service.SysRoleService;

 /**
 * </b>SysRoleController<br>
 * @author my
 * @version:1.0
 */
@Controller
@RequestMapping("/system/sysRole")
public class SysRoleController extends BaseController{
		private static Logger LOGGER = LoggerFactory.getLogger(SysRoleController.class);
	
  		@Autowired
  		private SysRoleService sysRoleService;
  		
  		/**
		  * 
		  * @Title: queryPageList
		  * @Description: 列表页面
		  * @param @param searchEntity
		  * @param @param pagination
		  * @return ModelAndView    返回类型
		  * @throws
		*/
		@RequestMapping(value = "/queryPageList")
		public ModelAndView queryPageList(SysRole sysRole, Pagination<SysRole> pagination) {
			LOGGER.debug(SysRoleController.class.getName()+":开始查询分页数据！");
			ModelAndView mv = new ModelAndView( "system/sysRole/sysRoleList" );
			pagination = this.sysRoleService.queryPageList( sysRole, pagination );
			mv.addObject( "pagination", pagination );
			return mv;
		}
		
		
		/**
		 * 
		 * @Title: toMerge
		 * @Description: 新增或修改页面
		 * @param @param entity
		 * @return ModelAndView    返回类型
		 * @throws
		 */
		@RequestMapping(value = "/toMerge")
		public ModelAndView toMerge(SysRole entity){
			ModelAndView mv = new ModelAndView("system/sysRole/sysRoleMerge");
			if(entity.getId()!= null){
				SysRole sysRole =  this.sysRoleService.get( entity.getId() ) ;
				mv.addObject("sysRole",sysRole);
			}else{
				mv.addObject("sysRole", new SysRole());
			}
			return mv;
		}

		/**
		 * 
		* @Title: doMerge
		* @Description: 新增或修改数据 
		* @param @param request
		* @param @param entity
		* @return ModelAndView    返回类型
		* @throws
		 */
		@RequestMapping(value = "/doMerge")
		public ModelAndView doMerge(HttpServletRequest request, SysRole entity,RedirectAttributes redirectAttributes) {
			if (entity.getId()!=null) {
				LOGGER.debug(SysRoleController.class.getName()+":开始更新数据！");
				this.addMessage(redirectAttributes, "修改数据成功");
				this.sysRoleService.update( entity );
			} else {
				LOGGER.debug(SysRoleController.class.getName()+":开始新增数据！");
				this.sysRoleService.add( entity );
				this.addMessage(redirectAttributes, "新增据成功");
			}
			return new ModelAndView( "redirect:/system/sysRole/queryPageList.do" );
		}

		/**
		 * 
		 * @Title: delete
		 * @Description:删除数据
		 * @param @param id
		 * @return ModelAndView    返回类型
		 * @throws
		 */
		@RequestMapping(value = "/delete")
		public ModelAndView delete(Long id,RedirectAttributes redirectAttributes) {
			LOGGER.debug(SysRoleController.class.getName()+":开始删除数据！");
	        this.sysRoleService.delete( id );
	        this.addMessage(redirectAttributes, "删除数据成功");
	        return new ModelAndView( "redirect:/system/sysRole/queryPageList.do" );
		}
}

